//
//  AFHTTP.m
//  xiaoTest
//
//  Created by Xiaoshiheng_pro on 2016/12/10.
//  Copyright © 2016年 xiao_shoubao. All rights reserved.
//

#import "AFHTTP.h"


@implementation AFHTTP


#pragma mark - GET请求无缓存
+ (NSURLSessionTask *)GET:(NSString *)URL
                        parameters:(NSDictionary *)parameters
                           success:(HttpRequestSuccess)success
                           failure:(HttpRequestFailed)failure{
    
    
    NSString  *requestUrl = kStringFormat(@"%@%@",@"?act=",URL);
    [requestUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    return  [self requestGETWithServerPath:HTTPAPI Headers:nil relativePath:requestUrl parameters:[self JMWithStringUrl:URL parameters:parameters] responseCacheBlock:nil successBlock:success failureBlock:failure];
    
}
#pragma mark - POST请求无缓存
+ (NSURLSessionTask *)POST:(NSString *)URL
                         parameters:(NSDictionary *)parameters
                            success:(HttpRequestSuccess)success
                            failure:(HttpRequestFailed)failure{
    
    
    NSString  *requestUrl = kStringFormat(@"%@%@",@"?act=",URL);
    [requestUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    return  [self requestPOSTWithServerPath:HTTPAPI Headers:nil relativePath:requestUrl parameters:[self JMWithStringUrl:URL parameters:parameters] responseCacheBlock:nil successBlock:success failureBlock:failure];
    
}


#pragma mark - POST请求无缓存  带图片
+ (NSURLSessionTask *)POST:(NSString *)URL
                parameters:(NSDictionary *)parameters
                    photos:(NSArray <UIImage *>*)photos
                photoNames:(NSArray*)photoNames
                   success:(HttpRequestSuccess)success
                   failure:(HttpRequestFailed)failure{
    
    
    NSString  *requestUrl = kStringFormat(@"%@%@",@"?act=",URL);
    [requestUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    return [self uploadWithServerPath:HTTPAPI Headers:nil relativePath:requestUrl parameters:[self JMWithStringUrl:URL parameters:parameters] photos:photos photoNames:photoNames progress:nil success:success failure:failure];
    
    
}



#pragma mark - GET请求缓存
+ (NSURLSessionTask *)GET:(NSString *)URL
               parameters:(NSDictionary *)parameters
       responseCacheBlock:(HttpRequestCache)responseCache
                  success:(HttpRequestSuccess)success
                  failure:(HttpRequestFailed)failure{
    
    NSString  *requestUrl = kStringFormat(@"%@%@",@"?act=",URL);
    [requestUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    return  [self requestGETWithServerPath:HTTPAPI Headers:nil relativePath:requestUrl parameters:[self JMWithStringUrl:URL parameters:parameters] responseCacheBlock:responseCache successBlock:success failureBlock:failure];
    
}
#pragma mark - POST请求缓存
+ (NSURLSessionTask *)POST:(NSString *)URL
                parameters:(NSDictionary *)parameters
        responseCacheBlock:(HttpRequestCache)responseCache
                   success:(HttpRequestSuccess)success
                   failure:(HttpRequestFailed)failure{
    
    NSString  *requestUrl = kStringFormat(@"%@%@",@"?act=",URL);
    [requestUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    return  [self requestPOSTWithServerPath:HTTPAPI Headers:nil relativePath:requestUrl parameters:[self JMWithStringUrl:URL parameters:parameters] responseCacheBlock:responseCache successBlock:success failureBlock:failure];
    
}

@end
